package logic

import (
	"context"
	"novel-hub/models/mysql"

	"novel-hub/novelrpc/internal/svc"
	"novel-hub/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionAddLogic {
	return &CollectionAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectionAddLogic) CollectionAdd(in *novelrpc.CollectionAddRequest) (*novelrpc.CollectionAddResponse, error) {
	// todo: add your logic here and delete this line

	collection := mysql.Collection{
		UserId:  in.UserId,
		NovelId: in.NovelId,
	}

	if err := collection.Collection(mysql.DB); err != nil {
		return nil, err
	}
 
	return &novelrpc.CollectionAddResponse{
		CollectionId: int64(collection.ID),
	}, nil
}
